home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir24 / psi110g.zip / NRHDR.C < prev    next >
C/C++ Source or Header  |  1994-04-17  |  3KB  |  142 lines

  1. /* Functions for level 3 net/rom support
  2.  * Copyright 1989 Dan Frank, W9NK
  3.  */
  4. #include "global.h"
  5. #ifdef NETROM
  6. #include "mbuf.h"
  7. #include "timer.h"
  8. #include "ax25.h"
  9. #include "netrom.h"
  10. #include "lapb.h"
  11. #include <ctype.h>
  12.   
  13. /* Convert a net/rom network header to host format structure
  14.  * Return -1 if error, 0 if OK
  15.  */
  16.   
  17. int
  18. ntohnr3(hdr,bpp)
  19. register struct nr3hdr *hdr;    /* output structure */
  20. struct mbuf **bpp;
  21. {
  22.     int ttl;
  23.   
  24.     if(pullup(bpp,hdr->source,AXALEN) < AXALEN)
  25.         return -1;
  26.   
  27.     if(pullup(bpp,hdr->dest,AXALEN) < AXALEN)
  28.         return -1;
  29.   
  30.     if((ttl = PULLCHAR(bpp)) == -1)
  31.         return -1;
  32.   
  33.     hdr->ttl = ttl;
  34.   
  35.     return 0;
  36. }
  37.   
  38. /* Convert a host-format net/rom level 3 header into an mbuf ready
  39.  * for transmission.
  40.  */
  41.   
  42. struct mbuf *
  43. htonnr3(hdr)
  44. register struct nr3hdr *hdr;
  45. {
  46.     struct mbuf *rbuf;
  47.     register char *cp;
  48.   
  49.     if(hdr == (struct nr3hdr *) NULL)
  50.         return NULLBUF;
  51.   
  52.     /* Allocate space for return buffer */
  53.     if((rbuf = alloc_mbuf(NR3HLEN)) == NULLBUF)
  54.         return NULLBUF;
  55.   
  56.     rbuf->cnt = NR3HLEN;
  57.   
  58.     /* Now convert */
  59.     cp = rbuf->data;
  60.   
  61.     memcpy(cp,hdr->source,AXALEN);
  62.     cp[ALEN] &= ~E;     /* source E-bit is always off */
  63.     cp += AXALEN;
  64.     memcpy(cp,hdr->dest,AXALEN);
  65.     cp[ALEN] |= E;      /* destination E-bit always set */
  66.     cp += AXALEN;
  67.     *cp = hdr->ttl;
  68.   
  69.     return rbuf;
  70. }
  71.   
  72. /* Convert a net/rom routing broadcast destination subpacket from
  73.  * network format to a host format structure.  Return -1 if error,
  74.  * 0 if OK.
  75.  */
  76. int
  77. ntohnrdest(ds,bpp)
  78. register struct nr3dest *ds;
  79. struct mbuf **bpp;
  80. {
  81.     int quality;
  82.   
  83.     /* get destination callsign */
  84.     if(pullup(bpp,ds->dest,AXALEN) < AXALEN)
  85.         return -1;
  86.   
  87.     /* get destination alias */
  88.     if(pullup(bpp,ds->alias,ALEN) < ALEN)
  89.         return -1;
  90.     ds->alias[ALEN] = '\0';
  91.   
  92.     /* get best neighbor callsign */
  93.     if(pullup(bpp,ds->neighbor,AXALEN) < AXALEN)
  94.         return -1;
  95.   
  96.     /* get route quality */
  97.     if((quality = PULLCHAR(bpp)) == -1)
  98.         return -1;
  99.     ds->quality = uchar(quality);
  100.   
  101.     return 0;
  102. }
  103.   
  104. /* Convert a host-format net/rom destination subpacket into an
  105.  * mbuf ready for transmission as part of a route broadcast
  106.  * packet.
  107.  */
  108. struct mbuf *
  109. htonnrdest(ds)
  110. register struct nr3dest *ds;
  111. {
  112.     struct mbuf *rbuf;
  113.     register char *cp;
  114.   
  115.     if(ds == (struct nr3dest *) NULL)
  116.         return NULLBUF;
  117.   
  118.     /* Allocate space for return buffer */
  119.     if((rbuf = alloc_mbuf(NRRTDESTLEN)) == NULLBUF)
  120.         return NULLBUF;
  121.   
  122.     rbuf->cnt = NRRTDESTLEN;
  123.   
  124.     cp = rbuf->data;
  125.   
  126.     memcpy(cp,ds->dest,AXALEN);
  127.     cp += AXALEN;
  128.   
  129.     memcpy(cp,ds->alias,ALEN);
  130.     cp += ALEN;
  131.   
  132.     memcpy(cp,ds->neighbor,AXALEN);
  133.     cp += AXALEN;
  134.   
  135.     *cp = uchar(ds->quality);
  136.   
  137.     return rbuf;
  138. }
  139.   
  140. #endif /* NETROM */
  141.   
  142.